package Producer_Consumer;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:38917
 * Date:2025/4/13
 * Time:18:52
 */
public class Producer_Consumer {
    public static void main(String[] args) {
        MyArrayBlockingList array = new MyArrayBlockingList(1000);
        Thread thread1 = new Thread(()->{
            int n = 1;
            while (true){
                try {
                    array.put(n + "");
                    System.out.println("生产元素n = " + n++);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread thread2 = new Thread(()->{
            while (true){
                try {
                    System.out.println("消费元素n = " + array.take());
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        thread1.start();
        thread2.start();
    }
}
